package com.example.lenovo.democ;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class EditStuScoreActivity extends AppCompatActivity {
    private EditText edit_name, edit_android, edit_english;
    private Button modify;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_stu_score);

        //定义组件
        findViews();
        //初始化输入框信息
        initData();
        //修改学生分数信息
        ModifyStusScores();
    }

    /**
     * 修改学生分数
     */
    private void ModifyStusScores() {
        modify = findViewById(R.id.btn_modify);
        modify.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = edit_name.getText().toString();
                int android = new Integer(edit_android.getText().toString());
                int english = Integer.parseInt(edit_english.getText().toString());
                Intent intent = new Intent();
                intent.putExtra("NAME", name);
                intent.putExtra("ANDROID", android);
                intent.putExtra("ENGLISH", english);
                setResult(3001, intent);
                finish();
            }
        });
    }

    /**
     * 初始化输入框信息
     */
    private void initData() {
        String name = getIntent().getStringExtra("NAME");
        int android = getIntent().getIntExtra("ANDROID", 0);
        int english = getIntent().getIntExtra("ENGLISH", 0);
        edit_name.setText(name);
        edit_android.setText(String.valueOf(android));
        edit_english.setText(String.valueOf(english));

    }

    /**
     * 定义组件
     */
    private void findViews() {
        edit_name = findViewById(R.id.edit_name);
        edit_android = findViewById(R.id.edit_android);
        edit_english = findViewById(R.id.edit_english);

    }
}

